import * as api from './api'
export const crudOptions = (vm) => {
  return {
    // pagination: false,
    pageOptions: {
      compact: true
    },
    options: {
      tableType: 'vxe-table',
      stripe: false,
      rowKey: true, // 必须设置，true or false
      rowId: 'id',
      height: '100%', // 表格高度100%, 使用toolbar必须设置
      highlightCurrentRow: false,
      defaultExpandAll: true,
      treeConfig: {
        lazy: true,
        hasChild: 'has_children',
        loadMethod: ({ row }) => {
          return api.GetList({ parent: row.id, lazy: true }).then(ret => {
            return ret.data.data
          })
        },
        iconLoaded: 'el-icon-loading' // 美化loading图标
      }
    },
    rowHandle: {
      width: 250,
      view: {
        thin: true,
        text: '',
        show: false,
        disabled () {
          return !vm.hasPermissions('Retrieve')
        }
      },
      edit: {
        thin: true,
        text: '',
        show: false,
        disabled () {
          return !vm.hasPermissions('Update')
        }
      },
      remove: {
        thin: true,
        text: '',
        disabled () {
          return !vm.hasPermissions('Delete')
        }
      },
      custom: [
        {
          thin: true,
          text: '跳转',
          type: 'primary',
          size: 'mini',
          emit: 'createGraph'
        }, {
          thin: true,
          text: '配置路由',
          type: 'success',
          size: 'mini',
          emit: 'openRouteDialog' // 新增事件
        }, {
          thin: true,
          text: '参数查看',
          type: 'success',
          size: 'mini',
          emit: 'viewConfig' // 新增事件
        }, {
          thin: true,
          text: '参数查看',
          type: 'success',
          size: 'mini',
          emit: 'viewConfig' // 新增事件
        }
      ]
    },
    indexRow: {
      // 或者直接传true,不显示title，不居中
      title: '序号',
      align: 'center',
      width: 100
    },
    viewOptions: {
      componentType: 'form'
    },
    formOptions: {
      defaultSpan: 12 // 默认的表单 span
    },
    columns: [
      {
        title: 'ID',
        key: 'id',
        show: false,
        disabled: true,
        width: 90,
        form: {
          disabled: true
        }
      },
      {
        title: '算法名称',
        key: 'title',
        sortable: true,
        form: {
          component: {
            span: 12,
            props: {
              clearable: true
            },
            placeholder: '请输入算法名称'
          }
        }
      },
      {
        title: '算法描述',
        key: 'description',
        sortable: true,
        form: {
          component: {
            span: 12,
            props: {
              clearable: true
            },
            placeholder: '请输入算法描述'
          }
        }
      }
      // {
      //   title: '算法参数',
      //   key: 'data',
      //   sortable: true,
      //   form: {
      //     component: {
      //       span: 12,
      //       props: {
      //         clearable: true
      //       },
      //       placeholder: '请输入算法参数'
      //     }
      //   }
      // }
    ].concat(vm.commonEndColumns())
  }
}
